var $sys ={};
(function (sys) {

    var scriptPool = {},
        active = "local";
    
    var tools ={
        removeScript : function (type, name) {
            if(isEmptyProp(sys, type)){
                return;
            }
            if(scriptPool[type][name] ){
                if(scriptPool[type][name]["scriptclose"]){
                    scriptPool[type][name]["scriptclose"]();
                }
                delete scriptPool[type][name];
            }

        },

    }

    sys.init = function () {
        
    }
    sys.getBean = function (type,name) {
        DEBUG("get bean ["+type+","+name+"]");

        if (isEmptyProp(scriptPool, type)) {
            return;
        }
        var obj = scriptPool[type][name];
        if (!isNull(obj)) {
            DEBUG("get bean ["+name+"] success");
        }
        return obj;
    }
    sys.setBean = function (type, name, bean) {
        DEBUG("set bean ["+type+","+name+"]");
        if (isEmptyProp(scriptPool, type)) {
            scriptPool[type] = {};
        }

        scriptPool[type][name] = bean;

        sys.getBean(type, name);
    }
    sys.remove = function (type,name) {
        tools.removeScript(type,name);
    }
})($sys)
function isNull(obj) {
    return obj == null|| obj == undefined;
}
function isEmptyObject(obj){
    if(isNull(obj)){
        return true;
    }
    for(var name in obj){
        return false;
    }
    return true;
}
function isEmptyList(list) {
    return !isNull(list) &&list.length ==0;
}
function isEmpty(obj) {
    return isNull(obj) || isEmptyObject(obj) || isEmptyList();

}
function isBlank(str) {
    return isNull(str) || str.trim().length ==0;
}
function isEmptyProp(obj , prop) {
    return isEmptyObject(obj) || isNull(obj[prop]);
}
function isFunction(fn){
    return !!fn &&
        typeof fn != "string" &&
        !fn.nodeName &&
        fn.constructor != Array &&
        /^[\s[]?function/.test(fn + "");
}
function isArray(obj) {
    return !isNull(obj) && Object.prototype.toString.call(obj)=='[object Array]'
}
function formatStr(str, data) {
    if(isEmpty(data)){
        return str;
    }else if(isArray(data)){
        return str;
    }else{
        return str;
    }
}
function extendFn(son, father) {
    var Supper = function () {}
    Supper.prototype = father.prototype;
    son.prototype = new Supper();
    son.constructor = son;
}

function extendObj() {
    var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;

    // Handle a deep copy situation? /*如果第一个参数为boolean值，则取第二个参数为目标对象*/
    if ( target.constructor == Boolean ) {
        deep = target;
        target = arguments[1] || {};
        // skip the boolean and the target
        i = 2;
    }

    // Handle case when target is a string or something (possible in deep copy)
    /*如果目标参数不是object或者function，那么就有可能是深度copy,*/
    if ( typeof target != "object" && typeof target != "function" )
        target = {};

    // extend $ itself if only one argument is passed /*如果参数长度为1，则将参数表示的对象的属性和方法复? 制给$本身*/
    if ( length == i ) {
        target = this;
        --i;
    }

    for ( ; i < length; i++ )
        // Only deal with non-null/undefined values当参数都为非空时，
        if ( (options = arguments[ i ]) != null )
        // Extend the base object
            for ( var name in options ) {
                var src = target[ name ], copy = options[ name ];

                // Prevent never-ending loop /*防止死循环*/
                if ( target === copy )
                    continue;

                // Recurse if we're merging object values/*深度继承的实现*/
                if ( deep && copy && typeof copy == "object" && !copy.nodeType )
                    target[ name ] = extendObj( deep,
                        // Never move original objects, clone them
                        src || ( copy.length != null ? [ ] : { } )
                        , copy );

                // Don't bring in undefined values? /*正常情况下的继承实现*/
                else if ( copy !== undefined )
                    target[ name ] = copy;

            }

    // Return the modified object
    return target;
};
